package com.oyjd.business.listview.service;

import java.util.ArrayList;
import java.util.List;

import android.os.AsyncTask;

import com.oyjd.business.listview.vo.ListViewDemoVO;
import com.oyjd.framework.service.CallBack;

public class ListViewDemoService {

	private int page = 1;
	public int pageSize = 10;

	public void getFirstData(final CallBack back) {
		page = 1;
		new AsyncTask<Integer, Integer, List<ListViewDemoVO>>() {
			@Override
			protected List<ListViewDemoVO> doInBackground(Integer... params) {
				int page = params[0];
				int pageSize = params[1];

				List<ListViewDemoVO> list = new ArrayList<ListViewDemoVO>();
				for (int i = 0; i < page * pageSize; i++) {
					ListViewDemoVO vo = new ListViewDemoVO();
					vo.setName("阿基米德" + i);
					vo.setTitle("给我一个支点我将翘起地球");
					vo.setTime("时间:1886-05-13 09:43:21");
					vo.setPicUrl("http://imgcdn.ph.126.net/9EuLok4MrbYAUu89WopKPA==/6598200064609827765.jpg");
					list.add(vo);
				}
				return list;
			}

			@Override
			protected void onPostExecute(List<ListViewDemoVO> obj) {
				back.back(obj);
			}
		}.execute(page, pageSize);

	}

	public void getMoreData(final CallBack back) {
		page++;
		new AsyncTask<Integer, Integer, List<ListViewDemoVO>>() {
			@Override
			protected List<ListViewDemoVO> doInBackground(Integer... params) {
				int page = params[0];
				int pageSize = params[1];

				List<ListViewDemoVO> list = new ArrayList<ListViewDemoVO>();
				for (int i = (page - 1) * pageSize; i < page * pageSize; i++) {
					ListViewDemoVO vo = new ListViewDemoVO();
					vo.setName("阿基米德" + i);
					vo.setTitle("给我一个支点我将翘起地球");
					vo.setTime("时间:1886-05-13 09:43:21");
					vo.setPicUrl("http://imgcdn.ph.126.net/9EuLok4MrbYAUu89WopKPA==/6598200064609827765.jpg");
					list.add(vo);
				}
				return list;
			}

			@Override
			protected void onPostExecute(List<ListViewDemoVO> obj) {
				back.back(obj);
			}
		}.execute(page, pageSize);

	}
}
